package com.baor.web.controller.mall;

import com.baor.common.annotation.Log;
import com.baor.common.core.controller.BaseController;
import com.baor.common.core.domain.AjaxResult;
import com.baor.common.core.page.TableDataInfo;
import com.baor.common.enums.BusinessType;
import com.baor.common.utils.poi.ExcelUtil;
import com.baor.mall.domain.TBrand;
import com.baor.mall.service.ITBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品品牌Controller
 * 
 * @author ruoyi
 * @date 2025-07-18
 */
@RestController
@RequestMapping("/mall/brand")
public class TBrandController extends BaseController
{
    @Autowired
    private ITBrandService tBrandService;

    /**
     * 查询商品品牌列表
     */
    @PreAuthorize("@ss.hasPermi('mall:brand:list')")
    @GetMapping("/list")
    public TableDataInfo list(TBrand tBrand)
    {
        startPage();
        List<TBrand> list = tBrandService.selectTBrandList(tBrand);
        return getDataTable(list);
    }

    /**
     * 导出商品品牌列表
     */
    @PreAuthorize("@ss.hasPermi('mall:brand:export')")
    @Log(title = "商品品牌", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TBrand tBrand)
    {
        List<TBrand> list = tBrandService.selectTBrandList(tBrand);
        ExcelUtil<TBrand> util = new ExcelUtil<TBrand>(TBrand.class);
        util.exportExcel(response, list, "商品品牌数据");
    }

    /**
     * 获取商品品牌详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:brand:query')")
    @GetMapping(value = "/{commoBrandId}")
    public AjaxResult getInfo(@PathVariable("commoBrandId") Long commoBrandId)
    {
        return success(tBrandService.selectTBrandByCommoBrandId(commoBrandId));
    }

    /**
     * 新增商品品牌
     */
    @PreAuthorize("@ss.hasPermi('mall:brand:add')")
    @Log(title = "商品品牌", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TBrand tBrand)
    {
        return toAjax(tBrandService.insertTBrand(tBrand));
    }

    /**
     * 修改商品品牌
     */
    @PreAuthorize("@ss.hasPermi('mall:brand:edit')")
    @Log(title = "商品品牌", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TBrand tBrand)
    {
        return toAjax(tBrandService.updateTBrand(tBrand));
    }

    /**
     * 删除商品品牌
     */
    @PreAuthorize("@ss.hasPermi('mall:brand:remove')")
    @Log(title = "商品品牌", businessType = BusinessType.DELETE)
	@DeleteMapping("/{commoBrandIds}")
    public AjaxResult remove(@PathVariable Long[] commoBrandIds)
    {
        return toAjax(tBrandService.deleteTBrandByCommoBrandIds(commoBrandIds));
    }
}
